<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtheadercode.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Template_Recurring_Create extends Page
{
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $edDescTemp = null;
       public $cmbSchedChange = null;
       public $COMPLETION_TYPE = null;
       public $lblBeforeDue = null;
       public $cmbDaysMonthsReminder = null;
       public $edRemind = null;
       public $Label7 = null;
       public $checkRecurring = null;
       public $lblDueEveryUnit = null;
       public $lblDueEvery = null;
       public $lblDueUnit = null;
       public $edDue = null;
       public $cmbDaysMonthsEvery = null;
       public $edDueEvery = null;
       public $lblDue = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTJavaScript9 = null;
       public $JTJavaScript8 = null;
       public $JTJavaScript7 = null;
       public $Image1 = null;
       public $imgBack = null;
       public $btnDelDesc = null;
       public $btnAddDesc = null;
       public $edDesc = null;
       public $listDesc = null;
       public $JTDivDesc = null;
       public $JTGroupBox2 = null;
       public $JTDivType = null;
       public $btnDelType = null;
       public $btnAddType = null;
       public $edType = null;
       public $listType = null;
       public $JTGroupBox1 = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $compid = null;
       public $btnShowType = null;
       public $JTSiteTheme1 = null;
       public $btnShowDescription = null;
       public $cmbcompletion = null;
       public $Label3 = null;
       public $dpBasis = null;
       public $hiddenStyle = null;
       public $hiddenId = null;
       public $cmbDaysMonths2 = null;
       public $edDueEvery2 = null;
       public $cmbDaysMonths = null;
       public $edOthers = null;
       public $lblOther = null;
       public $memoComments = null;
       public $lblComments = null;
       public $cmbVendor = null;
       public $Label2 = null;
       public $edPrice = null;
       public $lblFixedPrice = null;
       public $cmbDesc = null;
       public $Label5 = null;
       public $cmbType = null;
       public $lblType = null;
       public $cmbSchedule = null;
       public $Label1 = null;
       function Template_Recurring_CreateJSLoad($sender, $params)
       {

       ?>
       cmbSchedChange();
       <?php

       }

       function checkRecurringJSChange($sender, $params)
       {

       ?>
       cmbSchedChange();
       <?php

       }

       function cmbScheduleJSChange($sender, $params)
       {

       ?>
       var check = document.getElementById('checkRecurring');

       var schedObj = document.getElementById('cmbSchedule');
       var sched = schedObj.value;

       var lblDueObj = document.getElementById('lblDue');
       var lblDueOuterObj = document.getElementById('lblDue_outer');

       var edDueObj = document.getElementById('edDue');
       var edDueOuterObj = document.getElementById('edDue_outer');

       var lblDueUnitObj = document.getElementById('lblDueUnit');
       var lblDueUnitOuterObj = document.getElementById('lblDueUnit_outer');
       //dpBasisObj
          var dpBasisouterObj = document.getElementById('dpBasis_outer');
             var calendarFiled1Obj = document.getElementById('f-calendar-field-1');
             var calendarTrigger1Obj = document.getElementById('f-calendar-trigger-1');

       var lblDueEveryObj = document.getElementById('lblDueEvery');
       var lblDueEveryOuterObj = document.getElementById('lblDueEvery_outer');

       var edDueEveryObj = document.getElementById('edDueEvery');
       var edDueEveryOuterObj = document.getElementById('edDueEvery_outer');

       var lblDueEveryUnitObj = document.getElementById('lblDueEveryUnit');
       var lblDueEveryUnitOuterObj = document.getElementById('lblDueEveryUnit_outer');

       var cmbDaysMonthsEveryObj = document.getElementById('cmbDaysMonthsEvery');
       var cmbDaysMonthsEveryOuterObj = document.getElementById('cmbDaysMonthsEvery_outer');
       var remind = document.getElementById('edRemind');

       if(sched=='Mileage')
       {
        lblDueObj.innerHTML = 'Due at:';
        lblDueUnitObj.innerHTML = 'Km';
        lblDueEveryUnitObj.innerHTML = 'Km';

        edDueOuterObj.style.left = '155px';
        edDueObj.style.visibility = 'visible';

        lblDueUnitOuterObj.style.left = '315px';
        lblDueUnitObj.style.visibility = 'visible';

        dpBasisouterObj.style.left = '470px';
        calendarFiled1Obj.style.visibility = 'hidden';
        calendarTrigger1Obj.style.visibility = 'hidden';

        lblDueEveryUnitOuterObj.style.left = '521px';
        cmbDaysMonthsEveryOuterObj.style.left = '700px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'visible';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '157px';
        lblDueEveryOuterObj.style.left = '358px';
        edDueEveryOuterObj.style.left = '417px';
        edDueEveryObj.style.width = '104px';

       }
       if(sched=='Hours')
       {
        lblDueObj.innerHTML = 'Due at:';
        lblDueUnitObj.innerHTML = 'Hours';
        lblDueEveryUnitObj.innerHTML = 'Hours';

        edDueOuterObj.style.left = '155px';
        edDueObj.style.visibility = 'visible';

        lblDueUnitOuterObj.style.left = '315px';
        lblDueUnitObj.style.visibility = 'visible';

        dpBasisouterObj.style.left = '470px';
        calendarFiled1Obj.style.visibility = 'hidden';
        calendarTrigger1Obj.style.visibility = 'hidden';

        lblDueEveryUnitOuterObj.style.left = '521px';
        cmbDaysMonthsEveryOuterObj.style.left = '700px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'visible';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '157px';
        lblDueEveryOuterObj.style.left = '358px';
        edDueEveryOuterObj.style.left = '417px';
        edDueEveryObj.style.width = '104px';
       }
       if(sched=='Time')
       {
        lblDueObj.innerHTML = 'Due date:';

        edDueOuterObj.style.left = '562px';
        edDueObj.style.visibility = 'hidden';
        lblDueUnitOuterObj.style.left = '684px';
        lblDueUnitObj.style.visibility = 'hidden';

        dpBasisouterObj.style.left = '155px';
        calendarFiled1Obj.style.visibility = 'visible';
        calendarTrigger1Obj.style.visibility = 'visible';

        lblDueEveryUnitOuterObj.style.left = '700px';
        cmbDaysMonthsEveryOuterObj.style.left = '470px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'visible';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '68px';
        lblDueEveryOuterObj.style.left = '328px';
        edDueEveryOuterObj.style.left = '389px';
        edDueEveryObj.style.width = '78px';
       }

       if(check.checked==true)
       {
        lblDueEveryObj.style.visibility = 'visible';
        edDueEveryObj.style.visibility = 'visible';
       }
       if(check.checked==false)
       {
        lblDueEveryObj.style.visibility = 'hidden';
        edDueEveryObj.style.visibility = 'hidden';
       }

       //REMINDER ME
       var lblBeforeDueObj = document.getElementById('lblBeforeDue');
       var lblBeforeDueOuterObj = document.getElementById('lblBeforeDue_outer');

       var cmbDaysMonthsReminderObj = document.getElementById('cmbDaysMonthsReminder');
       var cmbDaysMonthsReminderOuterObj = document.getElementById('cmbDaysMonthsReminder_outer');
       if(sched=='Mileage' || sched=='Hours')
       {
        cmbDaysMonthsReminderOuterObj.style.left = '516px';
        cmbDaysMonthsReminderObj.style.visibility = 'hidden';
        lblBeforeDueOuterObj.style.left = '319px';
       }

       if(sched=='Mileage')
       {
       lblBeforeDueObj.innerHTML = 'Km before due';
       }
       if(sched=='Hours')
       {
       lblBeforeDueObj.innerHTML = 'Hours before due';
       }

       if(sched=='Time')
       {
        cmbDaysMonthsReminderOuterObj.style.left = '229px';
        cmbDaysMonthsReminderObj.style.visibility = 'visible';
        lblBeforeDueOuterObj.style.left = '319px';
        lblBeforeDueObj.innerHTML = 'before due date';
       }

       return false;
       <?php

       }


       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnDelDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DescIndex = document.getElementById('listDesc').selectedIndex;
       var DescValue = document.getElementById('listDesc')[DescIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxDesc3(DescValue,comp);
       <?php

       }

       function btnAddDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddesc = document.getElementById('edDesc').value;
       var comp = document.getElementById('compid').value;
       AjaxDesc2(adddesc,comp);
       document.Template_Recurring_Create.edDesc.value = "";
       <?php

       }

       function btnShowDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDesc').Show();
       document.Template_Recurring_Create.edDesc.value = "";
       <?php

       }

       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxType3(TypeValue,compider3);


       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var comp = document.getElementById('compid').value;
       AjaxType2(addtype,comp);
       document.getElementById('edType').value = "";

       <?php

       }



       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
        document.getElementById('edType').value = "";
       <?php

       }


       function cmbcompletionJSChange($sender, $params)
       {
       ?>
       completionWindow();
       <?php


       }

       function btnCancelClick($sender, $params)
       {
       redirect('template_recurring_list.php?template_id='.$this->hiddenId->getValue().'&style='.$this->hiddenStyle->getValue());


       }


       function CompletionChange()
       {
       $completion = $this->cmbcompletion->getItemIndex();

       if($completion=="WorkOrder")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }

        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }

       }


       if($completion=="Payment")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }

        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }

       }

       if($completion=="None")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }

        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }

       }


       }



       function Template_Recurring_CreateCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $template = $_GET['template'];
       $style = $_GET['style'];


       $this->cmbSchedule->ItemIndex='Usage';

       if($template!=null || $template!='')
       $this->hiddenId->setValue($template);
       if($style!=null || $style!='')
       $this->hiddenStyle->setValue($style);


       $this->cmbDesc->Clear();
       $result_desc = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='task descriptions'");

        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbDesc->AddItem($row_desc['value'], null, $row_desc['value']);
        }

          // list description
        $this->listDesc->Clear();
         $result_d = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='task descriptions'");

        while($row_d = mysql_fetch_array($result_d))
        {
            $this->listDesc->AddItem($row_d['value'], null, $row_d['value']);
        }

        $this->cmbType->Clear();
        $this->cmbType->AddItem('--Select--', null, null);
        $this->cmbType->setItemIndex('--Select--');
        $result_type = mysql_query("select * from lookup_reminder_tbl where company_id='".$_SESSION['company_id']."' AND category='type'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

         //list type
       $this->listType->Clear();
       $result_t = mysql_query("select * from lookup_reminder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }



       $this->cmbVendor->Clear();
       $this->cmbVendor->AddItem('--Select--',null,null);
       $this->cmbVendor->setItemIndex('--Select--');
       $result_vendor = mysql_query("select vendor_name from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vendor = mysql_fetch_array($result_vendor))
        {
            $this->cmbVendor->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
        }

       $this->checkRecurring->Checked = false;

       $this->edDueEvery->Text='';
       $this->edOthers->Text='';
       $this->edPrice->Text='';
       $this->edDue->Text='';
       $this->edRemind->Text='';
       $this->edDescTemp->Lines=array();
       $this->memoComments->Lines=array();

       $this->CompletionChange();

       $this->imgBack->setLink('template_recurring_list.php?template_id='.$this->hiddenId->getValue().'&style='.$this->hiddenStyle->getValue());
       }



       function btnSubmitClick($sender, $params)
       {
       $time_save = null;
       $miles_save = null;
       $schedBy_save = null;

       if($this->cmbSchedule->getItemIndex()=='Time')
       {
       $time_save = $this->edDueEvery->Text;
       $schedBy_save = $this->cmbDaysMonthsEvery->getItemIndex();
       }
       if($this->cmbSchedule->getItemIndex()=='Mileage' || $this->cmbSchedule->getItemIndex()=='Hours')
       {
       $miles_save = $this->edDueEvery->Text;
       }


        //recurring time
       if($this->cmbSchedule->getItemIndex()=='Time')
       {
       $val = $this->edDueEvery->Text;
       $days_mos = $this->cmbDaysMonthsEvery->getItemIndex();
       }

       /*if($this->cmbSchedule->getItemIndex()=='Both')
       {
       $val = $this->edDueEvery2->Text;
       $days_mos = $this->cmbDaysMonths2->getItemIndex();
       }*/

       $basis = $this->dpBasis->Text;

       if($this->cmbSchedule->getItemIndex()!='Mileage' || $this->cmbSchedule->getItemIndex()!='Hours')
       {

       if($days_mos=='Days')
       {
       $date = date($basis);
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val." day");
       $due_date = date("Y-m-d", $date_computed);
       }

       if($days_mos=='Months')
       {
       $date = date($basis);
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val." month");
       $due_date = date("Y-m-d", $date_computed);
       }

       }




       $result_get_style = mysql_query("SELECT template_type FROM template_tbl WHERE template_id='".$this->hiddenId->getValue()."'");
       $row_style = mysql_fetch_array($result_get_style);

       $style_id = $this->hiddenStyle->getValue();
       $result_style = mysql_query("SELECT value FROM lookup_vehicle_tbl WHERE id='".$style_id."'") or die("ERROR STYLE ".mysql_error());
       $row_style = mysql_fetch_array($result_style);
       $style_name = $row_style['value'];

       if($this->cmbSchedule->getItemIndex()=='Mileage' || $this->cmbSchedule->getItemIndex()=='Hours')
       {
         $save_rem = "rem_usage,";
         $save_rem2 = "'".$this->edRemind->Text."',";
       }
       if($this->cmbSchedule->getItemIndex()=='Time')
       {
         $save_rem = "rem_by,rem_time,";
         $save_rem2 = "'".$this->cmbDaysMonthsReminder->getItemIndex()."','".$this->edRemind->Text."',";
       }
       if($this->checkRecurring->Checked == true)
       $recurring = '1';
       if($this->checkRecurring->Checked == false)
       $recurring = '0';

       if($style_id=='All')
       {
        $style_name = 'All';
       }

       $result_reminder = mysql_query("insert into template_recurring_tbl (company_id,
       template_id,
       template_style,
       style_id,
       recurring,
       schedule_by,
       due_usage,
       due_time,
       due_by,
       usage_basis,
       date_basis,
       computed_date,
       ".$save_rem."
       completion_window,
       type,
       description,
       price,
       vendor,
       comments)

       values('".$_SESSION['company_id']."',
       '".$this->hiddenId->getValue()."',
       '".$style_name."',
       '".$this->hiddenStyle->getValue()."',
       '".$recurring."',
       '".$this->cmbSchedule->getItemIndex()."',
       '".$miles_save."',
       '".$time_save."',
       '".$schedBy_save."',
       '".$this->edDue->Text."',
       '".$this->dpBasis->Text."',
       '".$due_date."',
       ".$save_rem2."
       'WorkOrder',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edDescTemp->Text."',
       '".$this->edPrice->Text."',
       '".$this->cmbVendor->getItemIndex()."',
       '".$this->memoComments->Text."')")or die("INSERT RECURRING_TASK - " . mysql_error());





       //INSERT INTO EACH VEHICLE OF CHOSEN TYPE
       $result_recurr = mysql_query("SELECT last_insert_id(id) as new_recurring_id FROM template_recurring_tbl ORDER BY id DESC");
       $row_recurr = mysql_fetch_array($result_recurr);

       $query_veh = "SELECT vehicle_id,curr_tracking_value FROM vehicle_tbl WHERE style_name='".$style_name."' AND company_id='".$_SESSION['company_id']."'";
       $result_veh = mysql_query($query_veh) or die("SELECT VEHICLES ".mysql_error());


       while($row_veh = mysql_fetch_array($result_veh))
       {
       $veh_id = $row_veh['vehicle_id'];
       if($this->checkRecurring->Checked==true)
       {
        $recurring = '1';
       }
       if($this->checkRecurring->Checked==false)
       {
        $recurring = '0';
       }

       $template_id = $this->hiddenId->getValue();

       $basis = $this->dpBasis->Text;
       $days_mos = $schedBy_save;
       $val = $time_save;

       if($recurring=='1')
       {

       if($days_mos=='Days')
       {
       $ctr_day = '0';
       $date = date($basis);


       do
       {
       $val_mul = $val * $ctr_day;
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val_mul." day");
       $due_date = date("Y-m-d", $date_computed);
       //die($val_mul."-".$val."-".$ctr_day."-".$date."-".$due_date);
       $ctr_day++;
       }
       while(date('Y-m-d')>$due_date);

       //die($val_mul."-".$val."-".$ctr_day."-".$date."-".$due_date);
       }

       if($days_mos=='Months')
       {
       $ctr_month = '0';
       $date = date($basis);
       do
       {
       $val_mul = $val * $ctr_month;
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val_mul." month");
       $due_date = date("Y-m-d", $date_computed);
       $ctr_month++;
       }
       while(date('Y-m-d')>$due_date);
       }


       //schedule base on Usage
       $curr_od = $row_veh['curr_tracking_value'];
       $due_od = $miles_save;

       $sched_by = $this->cmbSchedule->getItemIndex();

       if($sched_by=="Mileage" || $sched_by=="Hours")
       {
       $due = $this->edDue->Text;
       while($curr_od>$due)
       {
       $due+=$due_od;
       }
       $due_usage = $due;
       }
       elseif($sched_by=="Time")
       {
       $due_usage = '0';
       }
       //end schedule base on Usage


       }
       if($recurring=='0')
       {
        $due_date = date($basis);
        $due_usage = $this->edDue->Text;
       }

       $sched_by = $this->cmbSchedule->getItemIndex();

       if($sched_by=="Time" || $sched_by=="Both")
       {
       $date_due = $due_date;
       }

       if($sched_by=="Usage" || $sched_by=="Mileage" || $sched_by=="Hours")
       {
       $date_due = '0000-00-00';
       }
       //end schedule based on Time/Date



       if($sched_by=='Mileage' || $sched_by=='Hours')
       {
         $save_rem = "rem_hours,";
         $save_rem2 = "'".$this->edRemind->Text."',";
       }
       if($sched_by=='Time')
       {
         $save_rem = "rem_by,rem_time,";
         $save_rem2 = "'".$this->cmbDaysMonthsReminder->getItemIndex()."','".$this->edRemind->Text."',";
       }

       if($sched_by=='Mileage' || $sched_by=='Hours')
       {
         $save_every = "every_hours,";
         $save_every2 = "'".$miles_save."',";
       }
       if($sched_by=='Time')
       {
         $save_every = "every_by,every_date,";
         $save_every2 = "'".$schedBy_save."','".$time_save."',";
       }

       //10/18/2010 - changed flag_temp to recur_per_veh
       $query_ins_remin = "insert into veh_reminder_tbl (company_id,
       vehicle_id,
       schedule_by,
       due_hours,
       due_date,
       ".$save_rem."
       ".$save_every."
       completion_window,
       type,
       description,
       price,
       status2,
       recur_per_veh,
       recurring_id,
       template_id)

       values ('".$_SESSION['company_id']."',
       '".$veh_id."',
       '".$this->cmbSchedule->getItemIndex()."',
       '".$due_usage."',
       '".$date_due."',
       ".$save_rem2."
       ".$save_every2."
       'WorkOrder',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edDescTemp->Text."',
       '".$this->edPrice->Text."',
       'Pending',
       '".$recurring."',
       '".$row_recurr['new_recurring_id']."',
       '".$template_id."')";

       mysql_query($query_ins_remin) or die("INSERT REMINDER - " . mysql_error());
       }


       echo"<script language=javascript>
       var answer = confirm('Add another record?');
       if(answer)
       {
       window.location = 'template_recurring_create.php?template_id=".$this->hiddenId->getValue()."&style=".$this->hiddenStyle->getValue()."';
       }
       else
       {
       window.location = 'template_recurring_list.php?template_id=".$this->hiddenId->getValue()."&style=".$this->hiddenStyle->getValue()."';
       }
       </script>";



       //redirect('template_recurring_list.php?template_id='.$this->hiddenId->getValue().'&style='.$this->hiddenStyle->getValue());
       }










       function cmbScheduleChange($sender, $params)
       {
       /*$schedule = $this->cmbSchedule->getItemIndex();

       if($schedule=='Time')
       {
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->lblMilesHours->Visible=false;
       $this->lblOr->Visible=false;
       $this->cmbDaysMonths->Visible=true;
       $this->edDueEvery->Visible=true;
       $this->dpBasis->Visible=true;
       $this->dpBasis->Left=445;
       $this->lblfrm->Left=409;
       $this->lblfrm->Visible=true;
       $this->lblhours->Visible=false;

       }
       else if ($schedule=='Both')
       {
       $this->cmbDaysMonths->Visible=false;
       $this->edDueEvery2->Visible=true;
       $this->cmbDaysMonths2->Visible=true;
       $this->lblMilesHours->Visible=true;
       $this->lblOr->Visible=true;
       $this->dpBasis->Visible=true;
       $this->dpBasis->Left=612;
       $this->lblfrm->Visible=true;
       $this->lblfrm->Left=570;
       }
       else if ($schedule=='Usage')
       {
       $this->edDueEvery->Visible=true;
       $this->lblMilesHours->Visible=true;
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblOr->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblfrm->Visible=false;
       $this->lblhours->Visible=false;
       }
       else if ($schedule=='Hours')
       {
       $this->edDueEvery->Visible=true;
       $this->lblMilesHours->Visible=false;
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblOr->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblfrm->Visible=false;
       $this->lblhours->Visible=true;
       }
       */

       }

}

global $application;

global $Template_Recurring_Create;

//Creates the form
$Template_Recurring_Create=new Template_Recurring_Create($application);

//Read from resource file
$Template_Recurring_Create->loadResource(__FILE__);

//Shows the form
$Template_Recurring_Create->show();

?>